﻿using System;
using Office = Microsoft.Office.Core;
using OL = Microsoft.Office.Interop.Outlook;

namespace uTILLIty.Outlook.FlexFileAddIn
{
	public class FolderInfo : IComparable
	{
		public FolderInfo(OL.MAPIFolder folder, FolderInfo parent, StoreInfo store)
		{
			//FolderReference = new WeakReference(folder);
			FullName = folder.FullFolderPath;
			FolderId = folder.EntryID;
			Store = store;
			Name = folder.Name;
			Parent = parent;
		}

		public FolderInfo Parent { get; set; }
		public string Name { get; set; }
		public string FolderId { get; set; }
		public string FullName { get; set; }

		public StoreInfo Store { get; set; }

		public string ParentPath { get { return string.Format("{0}", (object)Parent ?? Store); } }

		public int CompareTo(object obj)
		{
			var target = obj as FolderInfo;
      if (target == null)
        return -1;
		  return GetHashCode().CompareTo(target.GetHashCode());
      //return String.Compare(Name, target.Name, StringComparison.InvariantCultureIgnoreCase);
		}

	  public override bool Equals(object obj)
	  {
	    return CompareTo(obj) == 0;
	  }

	  public override int GetHashCode()
	  {
	    return FolderId.GetHashCode();
	  }

	  public override string ToString()
		{
			if (Parent == null)
				return string.Format("{0} < {1}", Name, Store);

			return string.Format("{0} < {1}", Name, Parent);
		}
	}
}